package com.example.mypc.fragmentdemo;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends FragmentActivity implements MyListFragment.ListTOMainInterface{

    private boolean isTab = false;//如果为true则是平板电脑;
    private MyDetailsFragment mdf;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mdf = (MyDetailsFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_detail);
        if (mdf!=null){
            isTab = true;
        }
    }

    @Override
    public void selected(int position) {
        Toast.makeText(this,""+position,Toast.LENGTH_LONG).show();
        if (isTab){
            if (mdf!=null){
                mdf.setSelectedOne(position);
            }
        }else{
            Intent intent = new Intent(this,SecondActivity.class);
            intent.putExtra(SecondActivity.POSITION_TAG,position);
            startActivity(intent);
        }
    }
}
